package databases

import (
	"time"
	"github.com/go-xorm/xorm"
	"permission/config"
	"permission/vigo_loger"
	"gitlab.gaodun.com/golib/gderror"
)

type Tpo_Sys_Users_Login struct {
	Id         int64 `xorm:"pk autoincr"`
	User_id    int64
	Login_ip   string
	Login_time time.Time `xorm:"DateTime"`
	App_id     int32
}

type UsersLoginFactory struct {
	Table         Tpo_Sys_Users_Login
	engine        *xorm.Engine
	RowsSlicePtr  []Tpo_Sys_Users_Login
}

// 返回 user factory
func NewUserLoginFactory() *UsersLoginFactory {
	userFac := UsersLoginFactory{}
	userFac.engine, _ = config.InitEng()
	return &userFac
}

func (ulf *UsersLoginFactory) Add() (int64, error) {
	res, err := ulf.engine.Insert(&(ulf.Table))
	if err != nil {
		vigo_loger.AddGrayLog(gderror.New(err.Error()).Error())
	}
	return res, err
}
